package android.bignerdranch.a2_1;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Timer;
import java.util.TimerTask;

public class UC3Activity extends AppCompatActivity {

    public FrameLayout frame;
    public ImageView iv1;
    public ImageView iv2;
    public ImageView iv3;
    public ImageView iv4;
    public ImageView iv5;
    public Button uc3_btn;
    int i = 0;

    private final Timer timer = new Timer();
    public TimerTask task;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch(msg.what)
            {
                case 1:
                    iv1.setImageResource(R.drawable.head1);
                case 2:
                    iv2.setImageResource(R.drawable.head2);
                case 3:
                    iv3.setImageResource(R.drawable.head3);
                case 4:
                    iv4.setImageResource(R.drawable.head4);
                case 5:
                    iv5.setImageResource(R.drawable.head5);
                default:
                    break;
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.uc3);

        task = new TimerTask() {
            @Override
            public void run() {
                Message message = new Message();
                message.what=1;
                handler.sendMessage(message);
            }
        };

        timer.schedule(task,5);

        iv1 = (ImageView)findViewById(R.id.iv1);
        iv2 = (ImageView)findViewById(R.id.iv2);
        iv3 = (ImageView)findViewById(R.id.iv3);
        iv4 = (ImageView)findViewById(R.id.iv4);
        iv5 = (ImageView)findViewById(R.id.iv5);
        uc3_btn = (Button)findViewById(R.id.uc3_btn);
        frame = (FrameLayout) findViewById(R.id.myframe);

        uc3_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(UC3Activity.this,MainActivity.class);
                startActivity(intent);
            }
        });


    }



}
